package com.GamersCom.db;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GenreDAO
{
	protected QueryMgr qm;
	
	public GenreDAO()
	{
		super();
		qm = new QueryMgr();
	}
	
	public void insert(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public void delete(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public void update(String query, List paramList) throws SQLException
	{
		qm.executePreparedQuery(query, paramList);
	}
	
	public List<Genre> getAll(String query) throws SQLException
	{
		List<Genre> list = new ArrayList<Genre>();
		
		ResultSet rs = qm.fetchList(query);
		
		if ( ! rs.isBeforeFirst() ) 
		{
			return null;
		}
		
		while ( rs.next() )
		{
			Genre genre = new Genre();
			genre.setName(rs.getString("name"));
			list.add(genre);
		}
		
		return list;
	}
	
	public Genre getGenre(String query, List paramList) throws SQLException 
	{
		ResultSet rs = qm.fetchList(query, paramList);
		Genre genre = new Genre();
		
		if ( !  rs.first() )
		{
			return null;
		}
		else 
		{
			genre.setName(rs.getString("name"));
		}
		
		return genre;		
	}
	
	
	
}
